
import 'dart:math';

import 'package:flutter/material.dart';

class MyPageRoute extends MaterialPageRoute {

	MyPageRoute({WidgetBuilder builder}) : super(builder: (context) =>
			Directionality(
				child: builder(context),
				textDirection: TextDirection.rtl,
			));

	@override
	Widget buildTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {

		return ClipOval(
			clipper: MyRect(ratio: animation.value),
			child: child,
		);
	}

	@override
	Animation<double> createAnimation() {
		// TODO: implement createAnimation
		var animation = Tween(begin: 0.0, end: 1.0).animate(controller);
		animation = CurvedAnimation(parent: animation, curve: Curves.easeInOutCirc);
		return animation;
	}

	@override
	AnimationController createAnimationController() {
		// TODO: implement createAnimationController
		return AnimationController(vsync: navigator, duration: Duration(milliseconds: 500));
	}
}

class MyRect extends CustomClipper<Rect> {
	final double ratio;

	MyRect({this.ratio});

	@override
	Rect getClip(Size size) {
		var max = size.width > size.height ? size.width : size.height;
		var value = ratio * sqrt(pow(size.width,2)+pow(size.height, 2));
		return Rect.fromLTWH((size.width / 2)-(value / 2), (size.height / 2)-(value / 2), value, value);
	}

	@override
	bool shouldReclip(MyRect oldClipper) => oldClipper.ratio != this.ratio;
}
